{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>添加审核员</legend>
    </fieldset>
    <form class="layui-form" action="">
        <div class="layui-form-item" style="margin-bottom: 0px">
            <div class="layui-inline" style="margin-right: 0px">
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" id="keyword" name="keyword" autocomplete="off"placeholder="请输入教师姓名/工号"class="layui-input">
                </div>
            </div>
            <div class="layui-inline" style="margin-right: 0px">
                <div class="layui-btn-group layui-inline" style="margin: 0px">
                    <a  href="{:url('lists')}" class="layui-btn layui-btn-primary">重置</a>
                    <button id="search" class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="formDemo" style="background-color: #009688;">
                        <i class="layui-icon">&#xe615;</i>查找
                    </button>
                </div>
            </div>
        </div>
    </form>

    <table class="layui-hide" id="test" lay-filter="list"></table>

</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs " lay-event="add1">设为一级审核员</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="add2">设为二级审核员</a>
</script>

{include file="common/foot"/}

<script>

    layui.use(['form', 'layer','table'], function(){
        var form = layui.form, layer = layui.layer,table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            elem: '#test'
            ,url:"{:url('check_search')}"
            ,method: 'post'
            ,page: true
            ,even:true
            ,cols: [[
                 {field:'teacher_no', width:150, title: '工号', sort: true}
                ,{field:'true_name', width:150, title: '用户名'}
                ,{width: 360, align: 'center', toolbar: '#barDemo'}
            ]]

            ,limit: 10 //每页默认显示的数量
        });
        //ajax请求数据
        $('#search').on('click', function () {
            var keyword = $('#keyword').val();
            if ($.trim(keyword) === '') {
                layer.msg('{:lang("pleaseEnter")}查找信息！', {icon: 0});
                return;
            }
            //表格重载
            tableIn.reload({
                //传递额外参数
                where: {keyword: keyword}

            });
        });


        table.on('tool(list)', function(obj){
            var data = obj.data;
            console.log(data.id);

            if(obj.event === 'add1'){
                layer.confirm('确定该教师为一级审核员？', function(index){
                    $.post("{:url('checkAdd')}",{id:data.id,flag:2},function(res){
                        if(res.code==1){
                            layer.msg(res.msg, {time:1000,icon: 1}, function () {
                                layer.close(index);
                                window.location.href = res.url;
                            });
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                });
            }
            if(obj.event === 'add2'){
                layer.confirm('确定该教师为二级审核员？', function(index){
                    $.post("{:url('checkAdd')}",{id:data.id,flag:1},function(res){
                        if(res.code==1){
                            layer.msg(res.msg, {time:1000,icon: 1}, function () {
                                layer.close(index);
                                window.location.href = res.url;
                            });
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                });
            }

        });

    });
</script>
